home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / grobda.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  8KB  |  264 lines

  1. /***************************************************************************
  2.  
  3.   machine.c
  4.  
  5.   Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  6.   I/O ports)
  7.  
  8. ***************************************************************************/
  9.  
  10. #include "driver.h"
  11. #include "cpu/m6809/m6809.h"
  12.  
  13. unsigned char *grobda_snd_sharedram;
  14. unsigned char *grobda_spriteram;
  15. unsigned char *grobda_customio_1,*grobda_customio_2;
  16. static int int_enable_1, int_enable_2;
  17. static int credits, coincounter1, coincounter2;
  18.  
  19. void grobda_init_machine( void )
  20. {
  21.     int_enable_1 = int_enable_2 = 1;
  22.     credits = coincounter1 = coincounter2 = 0;
  23.     cpu_set_halt_line(1, CLEAR_LINE);
  24. }
  25.  
  26. /* memory handlers */
  27. READ_HANDLER( grobda_snd_sharedram_r )
  28. {
  29.     return grobda_snd_sharedram[offset];
  30. }
  31.  
  32. WRITE_HANDLER( grobda_snd_sharedram_w )
  33. {
  34.     grobda_snd_sharedram[offset] = data;
  35. }
  36.  
  37. /* irq control functions */
  38. WRITE_HANDLER( grobda_interrupt_ctrl_1_w ){
  39.     int_enable_1 = offset;
  40. }
  41.  
  42. WRITE_HANDLER( grobda_interrupt_ctrl_2_w ){
  43.     int_enable_2 = offset;
  44. }
  45.  
  46. int grobda_interrupt_1( void ) {
  47.     if (int_enable_1)
  48.         return interrupt();
  49.     else
  50.         return ignore_interrupt();
  51. }
  52.  
  53. int grobda_interrupt_2( void ){
  54.     if (int_enable_2)
  55.         return interrupt();
  56.     else
  57.         return ignore_interrupt();
  58. }
  59.  
  60. WRITE_HANDLER( grobda_cpu2_enable_w )
  61. {
  62.     cpu_set_halt_line(1, offset ? CLEAR_LINE : ASSERT_LINE);
  63. }
  64.  
  65. /************************************************************************************
  66. *                                                                                    *
  67. *           Grobda custom I/O chips (preliminary)                                    *
  68. *                                                                                    *
  69. ************************************************************************************/
  70.  
  71. WRITE_HANDLER( grobda_customio_1_w )
  72. {
  73.     grobda_customio_1[offset] = data;
  74. }
  75.  
  76. WRITE_HANDLER( grobda_customio_2_w )
  77. {
  78.     grobda_customio_2[offset] = data;
  79. }
  80.  
  81. static int credmoned [] = { 1, 1, 1, 1, 2, 2, 3, 4 };
  82. static int monedcred [] = { 3, 4, 2, 1, 1, 3, 1, 1 };
  83.  
  84. READ_HANDLER( grobda_customio_1_r )
  85. {
  86.     int mode, val, temp1, temp2;
  87.  
  88.     mode = grobda_customio_1[8];
  89.  
  90.     if (mode == 3)    /* normal mode */
  91.     {
  92.         switch (offset)
  93.         {
  94.             case 0:     /* Coin slots */
  95.             {
  96.                 static int lastval;
  97.  
  98.                 val = (readinputport( 2 ) >> 4) & 0x03;
  99.                 temp1 = readinputport( 0 ) & 0x07;
  100.                 temp2 = (readinputport( 0 ) >> 5) & 0x07;
  101.  
  102.                 /* bit 0 is a trigger for the coin slot 1 */
  103.                 if ((val & 1) && ((val ^ lastval) & 1))
  104.                 {
  105.                     coincounter1++;
  106.                     if (coincounter1 >= credmoned[temp1])
  107.                     {
  108.                         credits += monedcred [temp1];
  109.                         coincounter1 -= credmoned [temp1];
  110.                     }
  111.                 }
  112.                 /* bit 1 is a trigger for the coin slot 2 */
  113.                 if ((val & 2) && ((val ^ lastval) & 2))
  114.                 {
  115.                     coincounter2++;
  116.                     if (coincounter2 >= credmoned[temp2])
  117.                     {
  118.                         credits += monedcred [temp2];
  119.                         coincounter2 -= credmoned [temp2];
  120.                     }
  121.                 }
  122.  
  123.                 if (credits > 99)
  124.                     credits = 99;
  125.  
  126.                 return lastval = val;
  127.             }
  128.                 break;
  129.             case 1:
  130.             {
  131.                 static int lastval;
  132.  
  133.                 val = readinputport( 2 ) & 0x03;
  134.                 temp1 = readinputport( 0 ) & 0x07;
  135.                 temp2 = (readinputport( 0 ) >> 5) & 0x07;
  136.  
  137.                 /* bit 0 is a trigger for the 1 player start */
  138.                 if ((val & 1) && ((val ^ lastval) & 1))
  139.                 {
  140.                     if (credits > 0)
  141.                         credits--;
  142.                     else
  143.                         val &= ~1;   /* otherwise you can start with no credits! */
  144.                 }
  145.                 /* bit 1 is a trigger for the 2 player start */
  146.                 if ((val & 2) && ((val ^ lastval) & 2))
  147.                 {
  148.                     if (credits >= 2)
  149.                         credits -= 2;
  150.                     else
  151.                         val &= ~2;   /* otherwise you can start with no credits! */
  152.                 }
  153.                 return lastval = val;
  154.             }
  155.                 break;
  156.             case 2:
  157.                 return (credits / 10);      /* high BCD of credits */
  158.                 break;
  159.             case 3:
  160.                 return (credits % 10);      /* low BCD of credits */
  161.                 break;
  162.             case 4:
  163.                 return (readinputport( 3 ) & 0x0f);        /* 1P controls */
  164.                 break;
  165.             case 5:
  166.                 return (readinputport( 4 ) & 0x03);        /* 1P button 1 */
  167.                 break;
  168.             case 6:
  169.                 return (readinputport( 3 ) >> 4);        /* 1P controls (cocktail mode) */
  170.                 break;
  171.             case 7:
  172.                 return (readinputport( 4 ) & 0x0c) >> 2;/* 1P button 1 (cocktail mode) */
  173.                 break;
  174.             default:
  175.                 return 0x0f;
  176.         }
  177.     }
  178.     else if (mode == 5)  /* IO tests chip 1 */
  179.     {
  180.         switch (offset)
  181.         {
  182.             case 2:
  183.                 return 0x0f;
  184.                 break;
  185.             case 6:
  186.                 return 0x0c;
  187.             default:
  188.                 return grobda_customio_1[offset];
  189.         }
  190.     }
  191.     else if (mode == 1)    /* test mode controls */
  192.     {
  193.         switch (offset)
  194.         {
  195.             case 4:
  196.                 return (readinputport( 2 ) & 0x03);    /* start 1 & 2 */
  197.                 break;
  198.             case 5:
  199.                 return (readinputport( 3 ) &0x0f);    /* 1P controls */
  200.                 break;
  201.             case 7:
  202.                 return (readinputport( 4 ) & 0x03);    /* 1P button 1 */
  203.                 break;
  204.             default:
  205.                 return grobda_customio_1[offset];
  206.         }
  207.     }
  208.     return grobda_customio_1[offset];
  209. }
  210.  
  211. READ_HANDLER( grobda_customio_2_r )
  212. {
  213.     int val, mode;
  214.  
  215.     mode = grobda_customio_2[8];
  216.  
  217.     if (mode == 8)  /* IO tests chip 2 */
  218.     {
  219.         switch (offset)
  220.         {
  221.             case 0:
  222.                 return 0x06;
  223.                 break;
  224.             case 1:
  225.                 return 0x09;
  226.                 break;
  227.             default:
  228.                 return grobda_customio_2[offset];
  229.         }
  230.     }
  231.     else if (mode == 9)
  232.     {
  233.         switch (offset)
  234.         {
  235.             case 0:
  236.                 val = (readinputport( 1 ) & 0x03);            /* lives */
  237.                 val |= (readinputport( 0 ) & 0x18) >> 1;    /* rank */
  238.                 break;
  239.             case 1:
  240.                 val = (readinputport( 2 ) >> 6) & 0x01;        /* attrack mode sound */
  241.                 val |= (readinputport( 1 ) >> 1) & 0x02;    /* select mode */
  242.                 val |= (readinputport( 1 ) & 0xc0) >> 4;    /* bonus life */
  243.                 break;
  244.             case 2:
  245.                 val = (readinputport( 0 ) & 0x07) << 1;        /* coinage A */
  246.                 break;
  247.             case 4:
  248.                 val = (readinputport( 0 ) & 0xe0) >> 5;        /* coinage B */
  249.                 break;
  250.             case 6:
  251.                 val = readinputport( 1 ) & 0x08;            /* test mode */
  252.                 val |= (readinputport( 4 ) & 0x20) >> 5;    /* 1P button 2 */
  253.                 val |= (readinputport( 4 ) & 0x80) >> 6;    /* 1P button 2 (cocktail mode) */
  254.                 val |= (readinputport( 2 ) & 0x80) >> 5;    /* cabinet */
  255.                 break;
  256.             default:
  257.                 val = 0x0f;
  258.         }
  259.         return val;
  260.     }
  261.     else
  262.         return grobda_customio_2[offset];
  263. }
  264.